package VMM;

import java.io.FileNotFoundException;
import java.io.IOException;

import Exceptions.BadFileEx;
import Exceptions.FrameOverflowEx;

/**
 * Driver class to setup the program.
 * 
 * @author allanwatson
 * 
 * @changelog 9/2/12 New design which makes the driver class responsible for
 *            creating the storage locations instead of the VMM class 18/2/12
 *            Adding catch statements for missing files
 * 
 */
public class Driver {

	public static void main(String[] args) throws BadFileEx,
			NumberFormatException {
		ITLB tlb = null;

		InputReader read = new InputReader();
		String dec = read
				.getString("Would you like to use FIFO or LRU for tlb?");
		int sizepT = read.getInt("Enter number of entries pageTable: ");
		int pageSize = read.getInt("Enter a page size: ");
		int frameNo = read.getInt("Enter number of frames in memory");
		int sizeTlb = read.getInt("Enter number of entries in TLB");


		PageTable pT = new PageTable(sizepT);
		PhysicalMem pM = new PhysicalMem(frameNo, pageSize);
		if (dec.toUpperCase().matches("FIFO"))
			tlb = new TLBfifo(sizeTlb);
		else if (dec.toUpperCase().matches("LRU"))
			tlb = new TLBlru(sizeTlb);

		try {

			VMM m = new VMM(pT, pM, tlb);
			Parser p = new Parser("InputFile.txt", m);
			p.readAddresses();
			p.readValues();
		} catch (FileNotFoundException e) {
			System.out.println("Files missing: Backing Storage or InputFile");
		} catch (IOException e) {
			e.printStackTrace();
		} catch (FrameOverflowEx e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}